#include "vertex.h"

#define ERROR 0.00001

Vertex::Vertex(int _id, bool _b) : id(_id), inBoundary(_b){
    selected = false;

    edge = NULL;
    edgeSignal = true;
}

Vertex::Vertex(int _id, Point _p, bool _b) : id(_id), inBoundary(_b), point(_p){
    selected = false;

    edge = NULL;
    edgeSignal = true;
}

Vertex::Vertex(int _id, Point _p, Edge *_e, bool _es, bool _b) : id(_id), inBoundary(_b), point(_p), edge(_e), edgeSignal(_es){
    selected = false;
}

Vertex::~Vertex(){
}

int Vertex::getID() const{
    return id;
}

void Vertex::select(bool _s){
    selected = _s;
}

bool Vertex::isSelected(){
    return selected;
}

void Vertex::setIsBoundary(bool _b){
    inBoundary = _b;
}

bool Vertex::isBoundary(){
    return inBoundary;
}

void Vertex::setPoint(Point &_p){
    point = _p;
}

Point Vertex::getPoint(){
    return point;
}

void Vertex::setEdge(Edge *_e, bool _es){
    edge = _e;
    edgeSignal = _es;
}

Edge *Vertex::getEdge(){
    return edge;
}

bool Vertex::getEdgeSignal(){
    return edgeSignal;
}

void Vertex::print() const{
    char signal;
    if(!edgeSignal) signal = '-';
    else signal = '+';
	std::cout << "V" << id;
	if(edge) std::cout << ";\t" << signal <<  "E" << edge->getID() << ";\t";
	else std::cout << ";\t" << ";\t";
	point.print();
	if(inBoundary) std::cout << ";\tÉ da borda!" <<std::endl;
}

bool lessThanByZ(Vertex *_v1, Vertex *_v2){
    if ((_v1->getPoint().z - ERROR <= _v2->getPoint().z) && (_v1->getPoint().z + ERROR >= _v2->getPoint().z)){//igual em z
        if((_v1->getPoint().x - ERROR <= _v2->getPoint().x) && (_v1->getPoint().x + ERROR >= _v2->getPoint().x)){//igual em x
            if((_v1->getPoint().y - ERROR <= _v2->getPoint().y) && (_v1->getPoint().y + ERROR >= _v2->getPoint().y)){//igual em y
                return true;
            }

            if (_v1->getPoint().y > _v2->getPoint().y) return true;
            return false;
        }

    if (_v1->getPoint().x > _v2->getPoint().x) return true;
        return false;
    }

    if (_v1->getPoint().z < _v2->getPoint().z) return true;
    return false;
}
